package com.project.contorller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
public class UploadController {
    @RequestMapping("upload")
    public String upload(@RequestParam("uploadImg") MultipartFile mf) throws IOException {
        //得到上传文件的名称
        String filename = mf.getOriginalFilename();
        //以时间毫秒数重命名上传文件，因防止上传文件同名导致覆盖
        filename=System.currentTimeMillis()+filename.substring(filename.lastIndexOf("."));
        mf.transferTo(new File("E:\\javaWeb\\pecject\\faceImg/"+filename));
        return filename;
    }
}
